package com.sgolub.commanndsonline.jobs;

import java.util.Date;
import java.util.Iterator;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sgolub.commanndsonline.ws.dao.AdvertisingRegistryOperationDAO;
import com.sgolub.commanndsonline.ws.entity.AdvertisingRegistryOperation;

/**
 * Scheduler for handling jobs
 */
@Service
public class SchedulerService {

	 protected static Logger logger = Logger.getLogger("service");
	 
	 @Autowired
	 @Qualifier("advertisingItemWorker")
	 private AdvertisingItemWorker advertisingItemWorker;
	 
	 @Autowired
	 @Qualifier("operationWorker")
	 private OperationWorker operationWorker;

	 @Autowired
		private AdvertisingRegistryOperationDAO daoSource;
	 
	 
	 @Scheduled(fixedDelay=600000) //60000 = 1 minute 3600000=1 hour 
	 public void doScheduleOperationWorker() {
	  logger.debug("Start schedule");
	   logger.debug("Delegate to worker ");
	   operationWorker.work();
	  logger.debug("End schedule");
	 }	 
	 
	 /**
	  * You can opt for cron expression or fixedRate or fixedDelay
	  * <p>
	  * Scheduled(fixedRate=5000)
	  * Scheduled(cron="       ")
	  * See Spring Framework 3 Reference:
	  * Chapter 25.5 Annotation Support for Scheduling and Asynchronous Execution
	  */
	 @Scheduled(fixedDelay=600000) //60000 = 1 minute
	 public void doScheduleAdvertisingItemWorker() {
	  logger.debug("Start schedule");
	   logger.debug("Delegate to worker ");
	   advertisingItemWorker.work();
	  logger.debug("End schedule");
	 }
	 

	 
}
